package org.startup.main;

import io.dropwizard.Application;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;

import org.startup.conf.AppConfiguration;
import org.startup.healthchecks.StartupHealthCheck;
import org.startup.resource.CustomerResource;

/**
 * Hello world!
 * 
 */
public class App extends Application<AppConfiguration> {
	public static void main(String[] args) {

		// List<Customer> list = new ArrayList<Customer>();
		// for (long i = 1; i <= 1000; i++) {
		// Customer customer = new Customer(i, "firsName" + i, "lastName" + i,
		// "gendar" + i, "address" + i, "country" + i, "email" + i
		// + "@email.com", "mobile" + i);
		// list.add(customer);
		//
		// }
		//
		// OutputStream outputStream = null;
		// try {
		// outputStream = new FileOutputStream(new File("customers.json"));
		// ObjectMapper mapper = new ObjectMapper();
		// mapper.writeValue(outputStream, list);
		// } catch (FileNotFoundException e1) {
		// e1.printStackTrace();
		// } catch (JsonGenerationException e) {
		// e.printStackTrace();
		// } catch (JsonMappingException e) {
		// e.printStackTrace();
		// } catch (IOException e) {
		// e.printStackTrace();
		// } finally {
		// if (outputStream != null) {
		// try {
		// outputStream.close();
		// } catch (IOException e) {
		// e.printStackTrace();
		// }
		// }
		// }

		
		
		try {
			new App().run(new String[] { "server", "startup.yml" });
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void initialize(Bootstrap<AppConfiguration> bootstrap) {

	}

	@Override
	public void run(AppConfiguration configuration, Environment environment)
			throws Exception {

		final StartupHealthCheck healthCheck = new StartupHealthCheck(
				configuration.getTemplate());
		environment.healthChecks().register("template", healthCheck);
		environment.jersey().register(new CustomerResource());
	}
}
